package org.dftproject.genesis.ui.pages.pedigree.icon;

import java.util.List;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.StackLayout;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Rectangle;

public class CenterStackLayout extends StackLayout {

	@Override
	public void layout(IFigure container) {
		Rectangle clientArea = container.getClientArea();
		
		@SuppressWarnings("unchecked")
		List<IFigure> children = container.getChildren();
		for (IFigure child : children) {
			Dimension size = child.getPreferredSize(clientArea.width, clientArea.height);
			child.setBounds(new Rectangle(clientArea.x + (clientArea.width - size.width) / 2, clientArea.y + (clientArea.height - size.height) / 2, size.width, size.height));
		}
	}

}
